package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐相关接口（用户端）
 */
@RestController
@RequestMapping("/user/setmeal")
@Api(tags = "套餐相关接口（用户端）")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询套餐")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result<List<Setmeal>> searchSetmealByCategory(@RequestParam Long categoryId) {
        List<Setmeal> data=setmealService.searchSetmealByCategory(categoryId);
        return Result.success(data);
    }
    /**
     * 根据套餐id查询套餐相关的菜品
     * @param setmealId 套餐id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询套餐相关的菜品接口")
    public Result<List<DishItemVO>> searchSetmealDish(@PathVariable("id") Long setmealId) {
        List<DishItemVO> data=setmealService.searchSetmealDish(setmealId);
        return Result.success(data);
    }
}
